package com.woniu.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.woniu.common.annotation.Log;
import com.woniu.common.core.controller.BaseController;
import com.woniu.common.core.domain.AjaxResult;
import com.woniu.common.enums.BusinessType;
import com.woniu.common.domain.DmsDrugModel;
import com.woniu.admin.service.IDmsDrugModelService;
import com.woniu.common.utils.poi.ExcelUtil;
import com.woniu.common.core.page.TableDataInfo;

import static com.woniu.common.core.domain.AjaxResult.success;

/**
 * 药品模板Controller
 * 
 * @author ruoyi
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/dms/drugModel")
public class DmsDrugModelController extends BaseController
{
    @Autowired
    private IDmsDrugModelService dmsDrugModelService;

    /**
     * 查询药品模板列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DmsDrugModel dmsDrugModel)
    {
        startPage();
        List<DmsDrugModel> list = dmsDrugModelService.selectDmsDrugModelList(dmsDrugModel);
        return getDataTable(list);
    }

    /**
     * 导出药品模板列表
     */
    @Log(title = "药品模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DmsDrugModel dmsDrugModel)
    {
        List<DmsDrugModel> list = dmsDrugModelService.selectDmsDrugModelList(dmsDrugModel);
        ExcelUtil<DmsDrugModel> util = new ExcelUtil<DmsDrugModel>(DmsDrugModel.class);
        util.exportExcel(response, list, "药品模板数据");
    }

    /**
     * 获取药品模板详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(dmsDrugModelService.selectDmsDrugModelById(id));
    }

    /**
     * 新增药品模板
     */
    @Log(title = "药品模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DmsDrugModel dmsDrugModel)
    {
        return toAjax(dmsDrugModelService.insertDmsDrugModel(dmsDrugModel));
    }

    /**
     * 修改药品模板
     */
    @Log(title = "药品模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DmsDrugModel dmsDrugModel)
    {
        return toAjax(dmsDrugModelService.updateDmsDrugModel(dmsDrugModel));
    }

    /**
     * 删除药品模板
     */
    @Log(title = "药品模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(dmsDrugModelService.deleteDmsDrugModelByIds(ids));
    }
}
